package net.flyinggroup.flights.controller;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MainController {
    @GetMapping("/")
    public String getIndex() {
        return "index";
    }

    @GetMapping("/whoami")
    @ResponseBody
    public Authentication whoami(Authentication authentication) {
        return authentication;
    }

    @PostMapping("/search")
    public String search(Model model) {
        model.addAttribute("flights", List.of("Flight one", "Flight two", "Flight three"));
        return "index";
    }
}